package cn.assumejson.springframework.common;

import cn.assumejson.springframework.beans.factory.BeansException;
import cn.assumejson.springframework.beans.factory.config.BeanPostProcessor;
import cn.assumejson.springframework.service.UserService;
import lombok.extern.slf4j.Slf4j;

/**
 * @author Mr. Li
 * @version 1.0
 * @since 1.0 2021/11/30 19:30
 */
@Slf4j
public class MyBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (beanName.equals("userService")) {
            UserService userService = (UserService) bean;
            userService.setLocation("MyBeanPostProcessor 执行为：成都");
            return userService;
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        log.info("{},Being executed", beanName);

        return bean;
    }
}
